package com.nanhai.buddhist.college.module.system.api.user;

import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.framework.common.util.collection.CollectionUtils;
import com.nanhai.buddhist.college.module.system.api.user.dto.AdminUserRespDTO;
import com.nanhai.buddhist.college.module.system.api.user.dto.TeacherUserCreatedReqDTO;
import com.nanhai.buddhist.college.module.system.api.user.dto.TeacherUserUpdatedReqDTO;
import com.nanhai.buddhist.college.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Api(tags = "RPC 服务 - 管理员用户")
public interface AdminUserApi {

    String PREFIX = ApiConstants.PREFIX + "/user";

    @GetMapping(PREFIX + "/get")
    @ApiOperation("通过用户 ID 查询用户")
    @ApiImplicitParam(name = "id", value = "用户编号", example = "1", required = true, dataTypeClass = String.class)
    CommonResult<AdminUserRespDTO> getUser(@RequestParam("id") String id);

    @GetMapping(PREFIX + "/list")
    @ApiOperation("通过用户 ID 查询用户们")
    @ApiImplicitParam(name = "ids", value = "部门编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<List<AdminUserRespDTO>> getUsers(@RequestParam("ids") Collection<String> ids);

    @GetMapping(PREFIX + "/list-by-dept-id")
    @ApiOperation("获得指定部门的用户数组")
    @ApiImplicitParam(name = "deptIds", value = "部门编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<List<AdminUserRespDTO>> getUsersByDeptIds(@RequestParam("deptIds") Collection<Long> deptIds);

    @GetMapping(PREFIX + "/list-by-post-id")
    @ApiOperation("获得指定岗位的用户数组")
    @ApiImplicitParam(name = "postIds", value = "岗位编号数组", example = "2,3", required = true, allowMultiple = true)
    CommonResult<List<AdminUserRespDTO>> getUsersByPostIds(@RequestParam("postIds") Collection<Long> postIds);

    /**
     * 获得用户 Map
     *
     * @param ids 用户编号数组
     * @return 用户 Map
     */
    default Map<String, AdminUserRespDTO> getUserMap(Collection<String> ids) {
        return CollectionUtils.convertMap(getUsers(ids).getCheckedData(), AdminUserRespDTO::getId);
    }

    @GetMapping(PREFIX + "/valid")
    @ApiOperation("校验用户们是否有效")
    @ApiImplicitParam(name = "ids", value = "用户编号数组", example = "3,5", required = true)
    CommonResult<Boolean> validUsers(@RequestParam("ids") Set<String> ids);


    @GetMapping(PREFIX + "/getTeacherCheckUser")
    @ApiOperation("获取教师审批人")
    @ApiImplicitParam(name = "ids", value = "用户编号数组", example = "3,5", required = true)
    CommonResult<List<AdminUserRespDTO>> getTeacherCheckUserByUser(@RequestParam("id") String id);

    @GetMapping(PREFIX + "/getAllList")
    @ApiOperation("获取所有用户列表")
    @ApiImplicitParam(name = "id", value = "用户编号", example = "1", required = true, dataTypeClass = String.class)
    CommonResult<List<AdminUserRespDTO>> getAllList();


    @GetMapping(PREFIX + "/initUserCollegeData")
    @ApiOperation("初始化用户数据")
    @ApiImplicitParam(name = "id", value = "用户编号", example = "1", required = true, dataTypeClass = String.class)
    CommonResult<Boolean> initUserCollegeData(@RequestParam("userId") String userId);


    @GetMapping(PREFIX + "/saveUserCollegeData")
    @ApiOperation("初始化用户数据")
    @ApiImplicitParam(name = "id", value = "用户编号", example = "1", required = true, dataTypeClass = String.class)
    CommonResult<Boolean> saveUserCollegeData(@RequestParam("userId") String userId, @RequestParam("type") Integer type, @RequestParam("parentId") String parentId, @RequestParam("id") String id);

    @GetMapping(PREFIX + "/checkRoleUser")
    @ApiOperation("校验权限是否绑定  id可为 ：学院 、 系部 、专业、 班级  ")
    @ApiImplicitParam(name = "id", value = "用户编号", example = "1", required = true, dataTypeClass = String.class)
    CommonResult<Boolean> checkRoleUser (@RequestParam("id") String id);

    @PostMapping(PREFIX + "/teacherUserCreated")
    @ApiOperation("教师创建 同步创建用户")
    CommonResult<String> teacherUserCreated(@RequestBody TeacherUserCreatedReqDTO reqDTO);

    @PostMapping(PREFIX + "/teacherUserUpdated")
    @ApiOperation("教师信息修改 同步修改用户")
    CommonResult<Boolean> teacherUserUpdated(@RequestBody TeacherUserUpdatedReqDTO reqDTO);


}
